package com.example.administrator.uitest.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import com.example.administrator.uitest.R;

/**
 * Created by Administrator on 2018/6/28 0028.
 */

public class HomeActivity extends Activity implements View.OnClickListener {
    private Button btn1,btn2, btn3, btn4;
    private Button level1,level2,level3,level4;
    private  AlertDialog alertDialog ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layoutjm);
        initView();


    }

    private void initLevelClick() {
        alertDialog = new AlertDialog.Builder(this).create();
        View dialog = LayoutInflater.from(this).inflate(R.layout.level_layout,null);
        alertDialog.setView(dialog);
        alertDialog.show();
        level1 = dialog.findViewById(R.id.level1);
        level2 = dialog.findViewById(R.id.level2);
        level3 = dialog.findViewById(R.id.level3);
        level4 = dialog.findViewById(R.id.level4);
        level1.setOnClickListener(this);
        level2.setOnClickListener(this);
        level3.setOnClickListener(this);
        level4.setOnClickListener(this);
    }
    @Override
    public void onClick(View view) {
        Display display = getWindowManager().getDefaultDisplay() ;
        int height = display.getHeight();

        Log.e("txh",""+height);
        Intent intent = new Intent(HomeActivity.this,MainActivity.class);
        int leveltime = 500;
        int leveldown = 2500;
        switch (view.getId()){
            case R.id.level1:leveltime = 500;leveldown = 2500;break;
            case R.id.level2:leveltime = 400;leveldown = 2000;break;
            case R.id.level3:leveltime = 300;leveldown = 1500;break;
            case R.id.level4:leveltime = 200;leveldown = 1000;break;
        }
        intent.putExtra("leveltime",leveltime);
        intent.putExtra("leveldown",leveldown+300);
        intent.putExtra("height",height);
        startActivity(intent);
        finish();
        alertDialog.dismiss();
    }

    private void initView() {
        btn1 = findViewById(R.id.btn1);
        btn3 = findViewById(R.id.btn3);
        btn2 = findViewById(R.id.btn2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(HomeActivity.this, ListActivity.class));
                finish();
            }
        });
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initLevelClick();
            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(HomeActivity.this, MineActivity.class));
                finish();

            }
        });

    }


}
